package com.base.invoke.response;

import java.io.Serializable;
import java.util.Collection;

/**
 * @desc 统一返回基础结果集(可被继承)
 * @param <T>
 * @author coolpig
 * @date 2019-09-27
 */
public class BaseResultBean<T> implements Serializable {

    private static final long serialVersionUID = -3397061562691321075L;

    private String code;
    private String message;
    private Collection<T> data;

    private BaseResultBean() {

    }

    public static BaseResultBean error(String code, String message) {
        BaseResultBean resultBean = new BaseResultBean();
        resultBean.setCode(code);
        resultBean.setMessage(message);
        return resultBean;
    }

    public static BaseResultBean success() {
        BaseResultBean resultBean = new BaseResultBean();
        resultBean.setCode("0");
        resultBean.setMessage("success");
        return resultBean;
    }

    public static <V> BaseResultBean<V> success(Collection<V> data) {
        BaseResultBean resultBean = new BaseResultBean();
        resultBean.setCode("0");
        resultBean.setMessage("success");
        resultBean.setData(data);
        return resultBean;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Collection<T> getData() {
        return data;
    }

    public void setData(Collection<T> data) {
        this.data = data;
    }
}
